<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <?php
            $tables = array(
                1=>'ats_city',
                2=>'ats_partners'
            );

            $tid = isset($_GET['tid']) ? $_GET['tid'] : 1;
            $tablename = $tables[$tid];
            $tabletitle = isset($_GET['t']) ? $_GET['t'] : '';
        ?>
        
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="keywords" content="jquery,ui,easy,easyui,web">
        <meta name="description" content="easyui help you build your web page easily!">
        <title><?php echo $tabletitle; ?></title>
        <link rel="stylesheet" type="text/css" href="css/easyui.css">
        <link rel="stylesheet" type="text/css" href="css/icon.css">
        <link rel="stylesheet" type="text/css" href="css/demo.css">
        <style type="text/css">
            #fm{
                margin:0;
                padding:10px 30px;
            }
            .ftitle{
                font-size:14px;
                font-weight:bold;
                color:#666;
                padding:5px 0;
                margin-bottom:10px;
                border-bottom:1px solid #ccc;
            }
            .fitem{
                margin-bottom:5px;
            }
            .fitem label{
                display:inline-block;
                width:80px;
            }
        </style>
        <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
        <script type="text/javascript">
            var url;
            function newData(){
                $('#dlg').dialog('open').dialog('setTitle','New Data');
                $('#fm').form('clear');
                url = 'editor_save.php';
            }
            function editData(){
                var row = $('#dg').datagrid('getSelected');
                if (row){
                    $('#dlg').dialog('open').dialog('setTitle','Edit Data');
                    $('#fm').form('load',row);
                    url = 'editor_update.php?id='+row.id;
                }
            }
            function saveData(){
                $('#fm').form('submit',{
                    url: url,
                    onSubmit: function(){
                        return $(this).form('validate');
                    },
                    success: function(result){
                        var result = eval('('+result+')');
                        if (result.success){
                            $('#dlg').dialog('close');
                            $('#dg').datagrid('reload');
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: result.msg
                            });
                        }
                    }
                });
            }
            function removeData(){
                var row = $('#dg').datagrid('getSelected');
                if (row){
                    $.messager.confirm('Confirm','Are you sure you want to remove this data?',function(r){
                        if (r){
                            $.post('editor_remove.php',{id:row.id},function(result){
                                if (result.success){
                                    $('#dg').datagrid('reload');
                                } else {
                                    $.messager.show({
                                        title: 'Error',
                                        msg: result.msg
                                    });
                                }
                            },'json');
                        }
                    });
                }
            }
        </script>
    </head>
    <body>
        

        <h2>Editor</h2>

        <?php
        session_start();
        if (!$_SESSION['tablename'])
            $_SESSION['tablename'] = '';

        $_SESSION['tablename'] = $tablename;

        include 'form_city.inc';
        ?>
        <div id="toolbar">
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newData()">New <?php echo $tabletitle; ?></a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editData()">Edit <?php echo $tabletitle; ?></a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeData()">Remove <?php echo $tabletitle; ?></a>
        </div>

        <div id="dlg" 
             class="easyui-dialog"
             style="width:400px;height:280px;padding:10px 20px"
             closed="true" buttons="#dlg-buttons">
            
            <div class="ftitle"><?php echo $tabletitle; ?></div>
            <form id="fm" method="post" novalidate>
                <?php
                include 'grid_city.inc';
                ?>
            </form>
        </div>
        <div id="dlg-buttons">
            <a href="#"
               class="easyui-linkbutton"
               iconCls="icon-ok"
               onclick="saveData()">Save</a>
            
            <a href="#"
               class="easyui-linkbutton"
               iconCls="icon-cancel"
               onclick="javascript:$('#dlg').dialog('close')">Cancel</a>
        </div>
    </body>
</html>